<!--
 * @作者: lqx
 * @LastEditors: lqx
 * @FilePath: \net-vue\src\view\topology\TopoMain.vue
-->
<template>
    <div style="height: 100%;width: 100%;">
        <div class="topo_main">
            <Topo :data="data" />
        </div>
    </div>
</template>

<script>
    import Topo from "../../components/topo/Topo";
    
    export default {
        name: "TopoMain",
        
        components: {Topo},
        data(){
            return{
                data:[]
            }
        },
        mounted(){
          this.getNodes();
        },
        methods:{
            getNodes() {
                let links = [];
                let nodeInfo = [];
                this.postRequest("/topo/topologyDiscovery")
                this.getRequest("/topo/connect").then(res => {
                    var link = {};
                    console.log(res);
                    for (let i = 0; i < res.length; i++) {
                        link = {
                            source: res[i].sip,
                            target: res[i].dip,
                            sif:res[i].sif,
                            dif:res[i].dif,
                            flow:"正常"+"  -------  "+"正常",
                            sfRate:res[i].sfRate,
                            dfRate:res[i].dfRate,
                            time:res[i].time,
                            label:{
                                align: 'middle',
                                fontSize: 12,
                                color:'#19d00f',
                            }
                        }
                        links.push(link)
                    }
                })
                this.getRequest("/topo/node").then(res=>{
                    console.log(res);
                    let n = {};
                    for (let i = 0; i < res.cpu.length; i++) {
                        if (res.systemInfo[i].typeName === '三层交换机') {
                            n = {
                                selfName: res.systemInfo[i].name,
                                name: res.systemInfo[i].ip,
                                selfDecs: res.systemInfo[i].selfDecs,
                                sysName: res.systemInfo[i].sysName,
                                typeName: res.systemInfo[i].typeName,
                                // cpuRate:res.cpu[i].cpuRate,
                                // memRate:res.memory[i].memRate,
                                // memAvailReal:res.memory[i].memAvailReal,//可使用量 Mb
                                // memTotalReal:res.memory[i].memTotalReal,//内存总量
                                category:0,
                                symbolSize: 30,
                                symbol: 'image://'+require('@/assets/img/huijuswitch.png'),
                                itemStyle: {
                                    normal: {
                                        color: '#19d00f',
                                    }
                                }
                            }
                        } else if (res.systemInfo[i].typeName === '服务器') {
                            n = {
                                selfName: res.systemInfo[i].name,
                                name: res.systemInfo[i].ip,
                                selfDecs: res.systemInfo[i].selfDecs,
                                sysName: res.systemInfo[i].sysName,
                                typeName: res.systemInfo[i].typeName,
                                cpuRate:res.cpu[i].cpuRate,
                                memRate:res.memory[i].memRate,
                                memAvailReal:res.memory[i].memAvailReal,//可使用量 Mb
                                memTotalReal:res.memory[i].memTotalReal,//内存总量
                                category:1,
                                symbolSize: 30,
                                symbol: 'image://',
                                itemStyle: {
                                    normal: {
                                        color: '#fff31a',
                                    }
                                }
                            }
                        } else if (res.systemInfo[i].typeName === '二层交换机') {
                            n = {
                                selfName: res.systemInfo[i].name,
                                name: res.systemInfo[i].ip,
                                selfDecs: res.systemInfo[i].selfDecs,
                                sysName: res.systemInfo[i].sysName,
                                typeName: res.systemInfo[i].typeName,
                                // cpuRate:res.cpu[i].cpuRate,
                                // memRate:res.memory[i].memRate,
                                // memAvailReal:res.memory[i].memAvailReal,//可使用量 Mb
                                // memTotalReal:res.memory[i].memTotalReal,//内存总量
                                symbolSize: 30,
                                category:2,
                                symbol: 'image://'+require('@/assets/img/twoswitch.png'),
                                itemStyle: {
                                    normal: {
                                        color: '#b5d0c9',
                                    }
                                }
                            }
                        } else {
                            n = {
                                //基本信息
                                name: res.systemInfo[i].ip,
                                selfName: res.systemInfo[i].name,
                                selfDecs: res.systemInfo[i].selfDecs,
                                sysName: res.systemInfo[i].sysName,
                                typeName: res.systemInfo[i].typeName,
                                //cpu
                                memTotalReal:res.memory[i].memTotalReal,//内存总量
                                //内存
                                cpuRate:res.cpu[i].cpuRate,
                                memRate:res.memory[i].memRate,
                                memAvailReal:res.memory[i].memAvailReal,//可使用量 Mb
                                category:3,
                                symbolSize: 30,
                                symbol: 'image://',
                                itemStyle: {
                                    normal: {
                                        color: '#5fd0cc',
                                    }
                                }
                            }
                        }
                        nodeInfo.push(n)
                    }
                })
                this.data.push(nodeInfo);
                this.data.push(links);
            }
        }
    }
</script>

<style scoped>
    .topo_main{
        height: 100%;
        width: 100%;
    }
</style>
